import maya.cmds as mc
import maya.mel as mel
import rosa_CreateJntForSpacePoint as rcj
import rosa_RigthreeSpanLeg as rrts
import rosa_RigFoot as rg
import RosaCommands as rc
import sys
reload(rc)
reload(rcj)
reload(rrts)
reload(rg)

def LegPlanFoot(dir,type):

        if dir=='Left' and type=='threeSpan':
                mc.parent( 'Left_foot01_fk_ctrl_zero' , 'Left_leg04_fk_ctrl' )
                mc.parent( 'Left_foot01_ikJnt' , 'Left_leg04_ik_jnt' )
                mc.parent( 'Left_foot01_drvJnt' , 'Left_leg04_drv_jnt' )
                mc.parent( 'Left_legGl_ikh_editGrp' , 'Left_ball_loc' )
                mc.parent( 'Left_foot_loc_pos' , 'Left_legik_ctrl' )
                mc.parent('Left_legik_ctrl_zero' , 'Left_footRig_grp' )
                mc.connectAttr('Left_legSetting_ctrl.ik_fk' , 'Left_footCmd_Bridge.ikfk' )
                rc.addNewAttr( 'Left_legik_ctrl'  , 0 ,-100 , 100 , '___footCmd' ,  'roll' , 'Side' , 'ballroll' , 'heelspin' , 'toespin' , 'toeroll' , 'toewiggle' )
                rc.lockhideAttr('Left_legik_ctrl' , 1 ,'___footCmd')

                mc.connectAttr('Left_legik_ctrl.roll' , 'Left_footCmd_Bridge.roll')
                mc.connectAttr('Left_legik_ctrl.Side' , 'Left_footCmd_Bridge.side')
                mc.connectAttr('Left_legik_ctrl.ballroll' , 'Left_footCmd_Bridge.ballroll')
                mc.connectAttr('Left_legik_ctrl.heelspin' , 'Left_footCmd_Bridge.heelspin')
                mc.connectAttr('Left_legik_ctrl.toespin' , 'Left_footCmd_Bridge.toespin')
                mc.connectAttr('Left_legik_ctrl.toeroll' , 'Left_footCmd_Bridge.toeroll')
                mc.connectAttr('Left_legik_ctrl.toewiggle' , 'Left_footCmd_Bridge.toewiggle')
                mc.connectAttr('Left_legSetting_ctrl.toelift' , 'Left_footCmd_Bridge.toelift')
                mc.connectAttr('Left_legSetting_ctrl.toestraight' , 'Left_footCmd_Bridge.toestraight')

        elif dir=='Right' and type=='threeSpan':

                mc.parent( 'Right_foot01_fk_ctrl_zero' , 'Right_leg04_fk_ctrl' )
                mc.parent( 'Right_foot01_ikJnt' , 'Right_leg04_ik_jnt' )
                mc.parent( 'Right_foot01_drvJnt' , 'Right_leg04_drv_jnt' )
                mc.parent( 'Right_legGl_ikh_editGrp' , 'Right_ball_loc' )
                mc.parent( 'Right_foot_loc_pos' , 'Right_legik_ctrl' )
                mc.parent('Right_legik_ctrl_zero' , 'Right_footRig_grp' )
                mc.connectAttr('Right_legSetting_ctrl.ik_fk' , 'Right_footCmd_Bridge.ikfk' )
                rc.addNewAttr( 'Right_legik_ctrl'  , 0 ,-100 , 100 , '___footCmd' ,  'roll' , 'Side' , 'ballroll' , 'heelspin' , 'toespin' , 'toeroll' , 'toewiggle' )
                rc.lockhideAttr('Right_legik_ctrl' , 1 ,'___footCmd')

                mc.connectAttr('Right_legik_ctrl.roll' , 'Right_footCmd_Bridge.roll')
                mc.connectAttr('Right_legik_ctrl.Side' , 'Right_footCmd_Bridge.side')
                mc.connectAttr('Right_legik_ctrl.ballroll' , 'Right_footCmd_Bridge.ballroll')
                mc.connectAttr('Right_legik_ctrl.heelspin' , 'Right_footCmd_Bridge.heelspin')
                mc.connectAttr('Right_legik_ctrl.toespin' , 'Right_footCmd_Bridge.toespin')
                mc.connectAttr('Right_legik_ctrl.toeroll' , 'Right_footCmd_Bridge.toeroll')
                mc.connectAttr('Right_legik_ctrl.toewiggle' , 'Right_footCmd_Bridge.toewiggle')
                mc.connectAttr('Right_legSetting_ctrl.toelift' , 'Right_footCmd_Bridge.toelift')
                mc.connectAttr('Right_legSetting_ctrl.toestraight' , 'Right_footCmd_Bridge.toestraight')

def TSfinalRig( ):



        rcj.finalCreateJnt('threeSpanLeg','on')

        rrts.rigThreeSpanLeg('Left')
        rg.rigfoot('Left')
        LegPlanFoot('Left','threeSpan')

        rrts.rigThreeSpanLeg('Right')
        rg.rigfoot('Right')
        LegPlanFoot('Right','threeSpan')

        mc.setAttr('skin_jnt_grp.visibility' , 1)
        mc.delete('threeSpanLeg_AutoRig_Panel_GRP')

        sys.stdout.write('----------------->>>>The three-span-legs Rigging has been completed  !<<<<-----------------' )
#TSfinalRig( )